<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8" isELIgnored="false"%>
 <%@taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c" %>
		
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>管理 | Bruce个人博客</title>


<!-- Bootstrap core CSS -->
<link	href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="signin.css" rel="stylesheet">

<link type="text/css" rel="stylesheet" href="./css/public.css" />
<link type="text/css" rel="stylesheet" href="./css/admin.css" />

<script src="./js/admin.js"></script>

</head>
<body>
	<div class="head_line"></div>
	<div class="container" id="main">
				
		<div id="header">
			<div>
				<h2><a href="/Blog/IndexServlet.do">Bruce个人博客-管理</a></h2>
				<h5 class="text-muted">有点粗糙 但能用就行</h5>
				</div>		
		</div>

				<div class="admin_div">
				<h4 class="btn btn-default">管理文章</h4>
				
				<c:forEach var="a" items="${articles}">				
				<div class="list-group-item">						
						<span>${a.title}</span>
						 <div class="r_div">	
						 <span>${a.time}</span>
						<button class="btn btn-default">&nbsp;<span class="glyphicon glyphicon-trash" style="color:#d9534f" onclick="edit_article(this,'${a.id}')"> 编辑</span>&nbsp;</button>
						 <button class="btn btn-default">&nbsp;<span class="glyphicon glyphicon-trash" style="color:#d9534f" onclick="delete_article(this,'${a.id}')"> 删除</span>&nbsp;</button>
						 </div>										 
				</div>							
				</c:forEach>					
				</div>

				<div class="admin_div">
				<h4 class="btn btn-default">管理分类</h4><h5 style="color:#d9534f" >删除分类会删除所有的文章</h5>
				<c:forEach var="s" items="${sort}">				
					<div class="list-group-item">
							<input type="text"  class="sort" id="input_${s}" value="${s}"   disabled="disabled" style="border:0px;"  >
							 <div class="r_div">
								 <button class="btn btn-default">&nbsp;<span class="glyphicon glyphicon-trash" style="color:#d9534f" onclick="edit_sort(this,'${s}')"> 编辑</span>&nbsp;</button>
								 <button class="btn btn-default">&nbsp;<span class="glyphicon glyphicon-trash" style="color:#d9534f" onclick="delet_sort(this,'${s}')">删除</span>&nbsp;</button>
							 </div>
					</div>
				</c:forEach>
				</div>
				
				<div class="admin_div">
				<h4 class="btn btn-default">管理标签</h4>
				<c:forEach var="t" items="${tags}">
				<div class="list-group-item">						
						<input type="text" class="tags" id="input_${t.tag}" value="${t.tag}"  disabled="disabled"  style="border:0px">
						 <div class="r_div">
							 <button class="btn btn-default">&nbsp;<span class="glyphicon glyphicon-trash" style="color:#d9534f" onclick="edit_tag(this,'${t.tag}')"> 编辑</span>&nbsp;</button>
						    <button class="btn btn-default">&nbsp;<span class="glyphicon glyphicon-trash" style="color:#d9534f" onclick="delet_tag(this,'${t.tag}')">删除</span>&nbsp;</button>
						 </div>										 
				  </div>
				</c:forEach>
				
				</div>


		<div class="foot_line"></div>		
		</div><!-- container -->		
		
</body>
</html>

<script type="text/javascript">
	function edit_article(span,articleId) {
		location.href="/Blog/GoEditArticleServlet.do?articleId="+articleId;

	}

	function delete_article(span,articleId) {
		if(confirm("确定要删除该文章吗?")){
			location.href="/Blog/DeleteArticleServlet.do?articleId="+articleId;
		}
	}

	function delet_sort(span,sortName) {
		if(confirm("确定要删除该文章分类吗(删除分类同时也会删除该分类下所有的文章，谨慎操作！)?")){
			location.href="/Blog/DeleteSortServlet.do?sortName="+sortName;
		}
	}
	//delet_tag(this,'${t.tag}
	function delet_tag(span,articleTag){
		if(confirm("确定要删除标签?")){
			location.href="/Blog/DeleteTagServlet.do?articleTag="+articleTag;
		}
	}
	function edit_sort(span,sortName) {
		if(confirm("确定更新"+sortName+"这个分类吗")){
			var newSort=window.prompt("请输入要更新的分类名：");
			location.href="/Blog/EditSortServlet.do?sortName="+sortName+"&newSort="+newSort;
		}

	}
	function edit_tag(span,tagName) {
		if(confirm("确定更新"+tagName+"这个标签吗")){
			var newTag=window.prompt("请输入要更新的分类名：");
			location.href="/Blog/EditTagServlet.do?tagName="+tagName+"&newTag="+newTag;
		}

	}

</script>